package com.lbw.aiTools;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Component;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Component
public class ExcelTools{

    @Tool(description = "将数据转换为Markdown表格，用户如果要求用表格样式输出就调用此方法")
    public String generateMarkdownTable(
            @ToolParam(description = "二维数组数据，每行需包含相同列数") List<List<String>> data) {
        log.info("调用工具：generateMarkdownTable，输入参数：{}", data);
        if (data == null || data.isEmpty()) {
            return "无数据";
        }

        // 动态生成表头和分隔线
        StringBuilder table = new StringBuilder();
        List<String> headers = data.get(0);
        table.append("| ").append(String.join(" | ", headers)).append(" |\n");
        table.append("| ").append(String.join(" | ", Collections.nCopies(headers.size(), "---"))).append(" |\n");

        // 填充数据行
        for (int i = 1; i < data.size(); i++) {
            List<String> row = data.get(i);
            table.append("| ").append(String.join(" | ", row)).append(" |\n");
        }

        return table.toString();
    }


}
